<?php

use console\db\Migration;

/**
 * 创建社交内容相关信息表
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class m180201_103000_t_social extends Migration {

    /**
     * {@inheritdoc}
     */
    public function up() {

        /**
         * 社交关系表
         * @table `user_relation`
         */
        $this->tableBuilder([
            'name' => 'user_relation',
            'comment' => '社交关系表',
            'columns' => [
                'id' => $this->primaryKey()->comment('用户ID'),
                'user_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('用户ID'),
                'to_user_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('关系用户ID'),
                'type' => $this->tinyint(1)->notNull()->defaultValue(0)->comment('关系类型，0关注，-1黑名单，1朋友'),
                'remark' => $this->string(30)->defaultValue('')->comment('备注名'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
            ],
            'index' => [
                [
                    'columns' => 'user_id',
                ],
                [
                    'columns' => 'to_user_id',
                ]
            ]
        ]);
    }

    /**
     * {@inheritdoc}
     */
    public function down() {
        $this->dropTable('{{%user_relation}}');
    }

}
